Skip to content

CS-10684: Fix test run instances being overwritten across factory iterations#4357

Merged
habdelra merged 2 commits intomainfrom
worktree-cs-10684-test-run-instances
Apr 9, 2026
Merged

CS-10684: Fix test run instances being overwritten across factory iterations#4357
habdelra merged 2 commits intomainfrom
worktree-cs-10684-test-run-instances

Conversation

@habdelra
Copy link
Copy Markdown
Contributor

@habdelra habdelra commented Apr 8, 2026

Summary

  • Fixes a bug where the factory loop created only one TestRun instance despite multiple test executions, because the realm search index hadn't indexed the previous TestRun before the next getNextSequenceNumber query
  • Added lastSequenceNumber floor parameter that callers track across iterations, ensuring Math.max(indexResult, lastSequenceNumber) + 1 always increments even when the search index is stale
  • Applied the fix to both buildTestRunner (factory loop path) and buildRunTestsTool (agent tool path)
  • Added regression test covering the stale-index scenario

Test plan

  • All 387 node tests pass
  • ESLint passes clean
  • No new type errors in changed files
  • Manual verification: run factory with multiple iterations and confirm separate TestRun instances with incrementing sequence numbers

🤖 Generated with Claude Code

…rations

The realm search index may not have indexed the TestRun from the previous
iteration by the time the next one queries getNextSequenceNumber, causing
it to return the same sequence number and overwrite the previous TestRun.

Add a lastSequenceNumber floor that callers track across iterations, so
Math.max(indexResult, lastSequenceNumber) + 1 always increments even when
the search index is stale.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a Software Factory bug where repeated test executions could overwrite the same TestRun card when the realm search index lags behind newly created runs, by allowing callers to provide a “floor” for sequence number allocation.

Changes:

  • Add lastSequenceNumber to ExecuteTestRunOptions and use it to compute Math.max(indexLatest, lastSequenceNumber) + 1 when creating a new TestRun.
  • Track and pass lastSequenceNumber across factory loop iterations and run_tests tool invocations to avoid reusing sequence numbers during stale indexing.
  • Add a regression unit test that simulates a stale search index returning no runs across consecutive calls.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/software-factory/tests/factory-test-realm.test.ts Adds regression test covering stale-index sequence reuse prevention via lastSequenceNumber.
packages/software-factory/scripts/lib/test-run-types.ts Extends execution options with lastSequenceNumber and documents stale-index behavior.
packages/software-factory/scripts/lib/test-run-execution.ts Applies lastSequenceNumber floor when computing the next TestRun sequence number.
packages/software-factory/scripts/lib/factory-tool-builder.ts Tracks lastSequenceNumber across run_tests tool calls and forwards it into execution.
packages/software-factory/scripts/lib/factory-implement.ts Tracks lastSequenceNumber across factory loop iterations and forwards it into execution.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…per-slug

- Add sequenceNumber to TestRunHandle and return it from resolveTestRun
  and executeTestRunFromRealm, eliminating fragile regex parsing of testRunId
- Track lastSequenceNumber per-slug in buildRunTestsTool using a Map,
  so different slugs get independent sequence floors

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@habdelra habdelra requested a review from a team April 8, 2026 15:43
@habdelra habdelra merged commit 60a5e5d into main Apr 9, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants